import { createSlice } from "@reduxjs/toolkit";

// 定义 slice 的初始状态
let initialState = {
  username: "",
  bio: "",
  avatar: "",
  errors: null,
  followers: [],
  following: false,
};

// 创建 profileSlice，用于管理登录相关的状态和 reducer
export const profileSlice = createSlice({
  name: "profile",
  initialState,
  reducers: {
    getProfile(state, actions) {
      return { ...state, ...actions.payload };
    },
    followResult(state, actions) {
      return { ...state, ...actions.payload };
    },
  },
});

// 导出对应的 action 创建函数，供组件中 dispatch 使用
export const { getProfile, followResult } = profileSlice.actions;
// 导出 slice 的 reducer，用于配置 Redux store
export default profileSlice.reducer;
